<html>
<head><meta charset="utf-8"><title>Type construction · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20construction.html">Type construction</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="236583938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20construction/near/236583938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bhargav Voleti <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20construction.html#236583938">(Apr 28 2021 at 21:28)</a>:</h4>
<p>I might be asking the wrong question, but I'm trying to understand how auto derives work. In my mind, the derive is applied when a type is constructed. Am I right in thinking that? If that's the case, can someone point me towards the code which does this?</p>



<a name="236584222"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20construction/near/236584222" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20construction.html#236584222">(Apr 28 2021 at 21:30)</a>:</h4>
<p>derives are a kind of macro, so they are expanded during macro expansion</p>



<a name="236584554"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20construction/near/236584554" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bhargav Voleti <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20construction.html#236584554">(Apr 28 2021 at 21:32)</a>:</h4>
<p>I'm thinking of auto triats like <code>Send</code> and <code>Sync</code>.</p>



<a name="236584632"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20construction/near/236584632" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bhargav Voleti <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20construction.html#236584632">(Apr 28 2021 at 21:33)</a>:</h4>
<p>Sorry should've specified auto traits in my original message, but it slipped my mind.</p>



<a name="236584825"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20construction/near/236584825" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20construction.html#236584825">(Apr 28 2021 at 21:34)</a>:</h4>
<p>ah, whether a type implements those traits depends on its contents</p>



<a name="236584995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20construction/near/236584995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20construction.html#236584995">(Apr 28 2021 at 21:35)</a>:</h4>
<p>so when the compiler needs to know whether the trait is implemented, it will recurse through the type's contents and check if they implement the trait</p>



<a name="236586151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20construction/near/236586151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bhargav Voleti <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20construction.html#236586151">(Apr 28 2021 at 21:47)</a>:</h4>
<p>To give some more context, I'm working on implementing the <code>#[must_not_suspend]</code> lint and the idea is for the attribute to propagate to any type which contains a type marked with the attribute. I'm adding a <code>TypeFlag</code> to ensure the presence of the attribute. The idea is to query for the presence of the type flag when a compound type is constructed and apply it to the enclosing type as well.</p>



<a name="236586175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20construction/near/236586175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bhargav Voleti <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20construction.html#236586175">(Apr 28 2021 at 21:48)</a>:</h4>
<p>Sorry if I'm not explaining things properly, as I suspect, I'm missing some context and not using the right terms.</p>



<a name="236681556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20construction/near/236681556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20construction.html#236681556">(Apr 29 2021 at 14:25)</a>:</h4>
<p>That's a separate mechanism from auto traits (which go through the full trait resoluion system, since there may be user-written impls)</p>



<a name="236681624"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20construction/near/236681624" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Aaron Hill <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20construction.html#236681624">(Apr 29 2021 at 14:26)</a>:</h4>
<p>Using <code>TypeFlags</code> sounds like the right idea for an attribute</p>



<a name="236701234"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Type%20construction/near/236701234" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Bhargav Voleti <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Type.20construction.html#236701234">(Apr 29 2021 at 16:08)</a>:</h4>
<p>I was thinking about it, and I think creating a new query for the presence of an attribute, the result of which can be computed from different source (checking for the presence of a flag, or querying the session in the HIR) would be more extensible. I noted that in a comment here: <a href="https://github.com/rust-lang/rust/issues/83310#issuecomment-828952064">https://github.com/rust-lang/rust/issues/83310#issuecomment-828952064</a></p>
<p>For the <code>#[must_not_suspend]</code> lint specifically, I still need to know where a <code>Ty</code> is constructed for a given type so that the flag can be propagated to that type as well.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>